package manager

import (
	"gitcode.com/G-YT/ANN/server/global"
	"gitcode.com/G-YT/ANN/server/model/common/request"
	"gitcode.com/G-YT/ANN/server/model/common/response"
	"gitcode.com/G-YT/ANN/server/model/manager"
	managerReq "gitcode.com/G-YT/ANN/server/model/manager/request"
	"gitcode.com/G-YT/ANN/server/service"
	"gitcode.com/G-YT/ANN/server/utils"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

type FdHealthManagerRegisterApi struct {
}

var fdHealthManagerRegisterService = service.ServiceGroupApp.ManagerServiceGroup.FdHealthManagerRegisterService

// CreateFdHealthManagerRegister 創建健康师注册
// @Tags FdHealthManagerRegister
// @Summary 創建健康师注册
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body manager.FdHealthManagerRegister true "創建健康师注册"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"創建成功"}"
// @Router /fdHealthManagerRegister/createFdHealthManagerRegister [post]
func (fdHealthManagerRegisterApi *FdHealthManagerRegisterApi) CreateFdHealthManagerRegister(c *gin.Context) {
	var fdHealthManagerRegister manager.FdHealthManagerRegister
	err := c.ShouldBindJSON(&fdHealthManagerRegister)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := fdHealthManagerRegisterService.CreateFdHealthManagerRegister(&fdHealthManagerRegister); err != nil {
		global.GVA_LOG.Error("創建失敗!", zap.Error(err))
		response.FailWithMessage("創建失敗", c)
	} else {
		response.OkWithMessage("創建成功", c)
	}
}

// DeleteFdHealthManagerRegister 删除健康师注册
// @Tags FdHealthManagerRegister
// @Summary 删除健康师注册
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body manager.FdHealthManagerRegister true "删除健康师注册"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /fdHealthManagerRegister/deleteFdHealthManagerRegister [delete]
func (fdHealthManagerRegisterApi *FdHealthManagerRegisterApi) DeleteFdHealthManagerRegister(c *gin.Context) {
	var fdHealthManagerRegister manager.FdHealthManagerRegister
	err := c.ShouldBindJSON(&fdHealthManagerRegister)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := fdHealthManagerRegisterService.DeleteFdHealthManagerRegister(fdHealthManagerRegister); err != nil {
		global.GVA_LOG.Error("删除失敗!", zap.Error(err))
		response.FailWithMessage("删除失敗", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeleteFdHealthManagerRegisterByIds 批量删除健康师注册
// @Tags FdHealthManagerRegister
// @Summary 批量删除健康师注册
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除健康师注册"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /fdHealthManagerRegister/deleteFdHealthManagerRegisterByIds [delete]
func (fdHealthManagerRegisterApi *FdHealthManagerRegisterApi) DeleteFdHealthManagerRegisterByIds(c *gin.Context) {
	var IDS request.IdsReq
	err := c.ShouldBindJSON(&IDS)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := fdHealthManagerRegisterService.DeleteFdHealthManagerRegisterByIds(IDS); err != nil {
		global.GVA_LOG.Error("批量删除失敗!", zap.Error(err))
		response.FailWithMessage("批量删除失敗", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// UpdateFdHealthManagerRegister 更新健康师注册
// @Tags FdHealthManagerRegister
// @Summary 更新健康师注册
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body manager.FdHealthManagerRegister true "更新健康师注册"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /fdHealthManagerRegister/updateFdHealthManagerRegister [put]
func (fdHealthManagerRegisterApi *FdHealthManagerRegisterApi) UpdateFdHealthManagerRegister(c *gin.Context) {
	var fdHealthManagerRegister manager.FdHealthManagerRegister
	err := c.ShouldBindJSON(&fdHealthManagerRegister)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := fdHealthManagerRegisterService.UpdateFdHealthManagerRegister(fdHealthManagerRegister); err != nil {
		global.GVA_LOG.Error("更新失敗!", zap.Error(err))
		response.FailWithMessage("更新失敗", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindFdHealthManagerRegister 用id査詢健康师注册
// @Tags FdHealthManagerRegister
// @Summary 用id査詢健康师注册
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query manager.FdHealthManagerRegister true "用id査詢健康师注册"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"査詢成功"}"
// @Router /fdHealthManagerRegister/findFdHealthManagerRegister [get]
func (fdHealthManagerRegisterApi *FdHealthManagerRegisterApi) FindFdHealthManagerRegister(c *gin.Context) {
	var fdHealthManagerRegister manager.FdHealthManagerRegister
	err := c.ShouldBindQuery(&fdHealthManagerRegister)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if refdHealthManagerRegister, err := fdHealthManagerRegisterService.GetFdHealthManagerRegister(fdHealthManagerRegister.ID); err != nil {
		global.GVA_LOG.Error("査詢失敗!", zap.Error(err))
		response.FailWithMessage("査詢失敗", c)
	} else {
		response.OkWithData(gin.H{"refdHealthManagerRegister": refdHealthManagerRegister}, c)
	}
}

// GetFdHealthManagerRegisterList 分页獲取健康师注册列表
// @Tags FdHealthManagerRegister
// @Summary 分页獲取健康师注册列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query managerReq.FdHealthManagerRegisterSearch true "分页獲取健康师注册列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"獲取成功"}"
// @Router /fdHealthManagerRegister/getFdHealthManagerRegisterList [get]
func (fdHealthManagerRegisterApi *FdHealthManagerRegisterApi) GetFdHealthManagerRegisterList(c *gin.Context) {
	var pageInfo managerReq.FdHealthManagerRegisterSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	storeID := utils.GetUserID(c)
	pageInfo.FdHealthManager.StoreId = storeID
	if list, total, err := fdHealthManagerRegisterService.GetFdHealthManagerRegisterInfoList(pageInfo); err != nil {
		global.GVA_LOG.Error("獲取失敗!", zap.Error(err))
		response.FailWithMessage("獲取失敗", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "獲取成功", c)
	}
}

// GetScHealthManagerRegisterList 獲取健康师注册列表【服务中心】
// @Tags FdHealthManagerRegister
// @Summary 獲取健康师注册列表【服务中心】
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query managerReq.FdHealthManagerRegisterSearch true "獲取健康师注册列表【服务中心】"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"獲取成功"}"
// @Router /fdHealthManagerRegister/getScHealthManagerRegisterList [get]
func (fdHealthManagerRegisterApi *FdHealthManagerRegisterApi) GetScHealthManagerRegisterList(c *gin.Context) {
	var pageInfo managerReq.FdHealthManagerRegisterSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	ScID := utils.GetUserID(c)
	if list, total, err := fdHealthManagerRegisterService.GetScHealthManagerRegisterList(pageInfo, ScID); err != nil {
		global.GVA_LOG.Error("獲取失敗!", zap.Error(err))
		response.FailWithMessage("獲取失敗", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "獲取成功", c)
	}
}

// GetAllHealthManagerRegisterList 分页獲取全部健康师注册列表【超管】
// @Tags FdHealthManagerRegister
// @Summary 分页獲取健康师注册列表【超管】
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query managerReq.FdHealthManagerRegisterSearch true "分页獲取全部健康师注册列表【超管】"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"獲取成功"}"
// @Router /fdHealthManagerRegister/getAllHealthManagerRegisterList [get]
func (fdHealthManagerRegisterApi *FdHealthManagerRegisterApi) GetAllHealthManagerRegisterList(c *gin.Context) {
	var pageInfo managerReq.FdHealthManagerRegisterSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, total, err := fdHealthManagerRegisterService.GetAllHealthManagerRegisterInfoList(pageInfo); err != nil {
		global.GVA_LOG.Error("獲取失敗!", zap.Error(err))
		response.FailWithMessage("獲取失敗", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "獲取成功", c)
	}
}
